<template>
  <el-dialog v-model="dialogFormVisible" title="千峰教育管理系统" width="300" center>
    <el-form :model="form">
      <el-form-item label="管理员用户名" label-width="100px">
        <el-input v-model="form.adminname" autocomplete="off" />
      </el-form-item>
      <el-form-item label="管理员密码" label-width="100px">
        <el-input v-model="form.password" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">重置</el-button>
        <el-button type="primary" @click="LoginFn">登录</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { loginReq } from '../api/login'
import { ElMessage } from 'element-plus'
// const vFocus = {
//   mounted: (el: any) => {
//     el.focus()
//   }
// }
const router = useRouter()
const dialogFormVisible = ref(true)

const form = reactive({
  adminname: '',
  password: ''
})
function LoginFn() {
  console.log(form)
  loginReq(form.adminname, form.password).then((res) => {
    console.log(res.data)
    if (res.data.code == 200) {
      localStorage.setItem('admin-token', res.data.data.token)
      ElMessage.success(res.data.message)
      router.push('/home')
    } else if (res.data.code == 10005) {
      ElMessage({
        showClose: true,
        message: res.data.message,
        type: 'warning'
      })
      router.push('/reg')
    } else {
      ElMessage.error(res.data.message)
    }
  })
}
</script>
<style lang="scss" scoped></style>
